﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using DataAccessLibrary;
using DataAccessLibrary.DAL;
using context;
using entities;

namespace BusinessLogicLibrary
{
    public class BookingModule
    {
        private readonly BookingDAO bookingDAO = new BookingDAO();

        public string CreateBooking(int pCustomerID, List<int> pRoomID, DateTime pCheckInDate, DateTime pCheckOutDate)
        {
            try
            {
                pCheckInDate = pCheckInDate.Date;
                pCheckOutDate = pCheckOutDate.Date;

                if (pCheckInDate < pCheckOutDate)
                {
                    return "ERROR: CheckIn date must be earlier than CheckOut date";
                }

                pCheckInDate = pCheckInDate.Add(new TimeSpan(12, 0, 0, 0));
                pCheckOutDate = pCheckOutDate.Add(new TimeSpan(11, 0, 0, 0));

                // Booking
                var booking = new Booking
                                  {
                                      CustomerID = pCustomerID,
                                      BookingDate = DateTime.Today
                                  };

                //CheckIn
                var lstCheckIn = pRoomID.Select(rID => new CheckIn
                                                           {
                                                               RoomID = rID,
                                                               CheckInDate = pCheckInDate,
                                                               CheckOutDate = pCheckOutDate,
                                                               Available = false
                                                           }).ToList();

                return bookingDAO.InsertBooking(booking, lstCheckIn);
            }
            catch (Exception ex)
            {
                return "FAIL: " + ex.Message;
            }
        }

        public string DeleteBooking(int pBookingId)
        {
            return bookingDAO.DeleteBooking(pBookingId);
        }

        public List<Booking> GetBookingByCustomerId(int customerId)
        {
            return bookingDAO.SelectBookingByCustomerId(customerId);
        }


    }
}
